package api.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

public class StringToMapUtils extends StringUtils {

    //method=loginMobile&loginname=abc&loginpass=abc
    //token=61b3590090982a0185dda9d3bd793b46;userId=123
    public static Map<String,Object> convertStrToMap(String str,String regx){
        //HashMap<String, Object> hashMap = new HashMap<>();
        HashMap<String, Object> hashMap = new LinkedHashMap<>();
        if (isNotBlank(str)) {
            String[] split = str.split(regx);
            for (String s : split) {
                String[] strings = s.split("=");
                if(strings.length==2){
                    hashMap.put(strings[0].trim(),strings[1].trim());
                }
            }
        }
        return hashMap;
    }

    //method=loginMobile&loginname=abc&loginpass=abc
    public static Map<String,Object> convert1(String str){
        return convertStrToMap(str,"&");
    }

    //token=61b3590090982a0185dda9d3bd793b46;userId=123
    public static Map<String,Object> convert2(String str){
        return convertStrToMap(str,";");
    }
}
